package cn.yx.common.core.enums;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Sentinel异常枚举</p>
 *
 * @author Wgssmart
 */
public enum SentinelExceptionEnum {

    /**
     * Sentinel流控
     */
    SENTINEL_BLOCK_EXCEPTION("SentinelBlockException", "cn.yx.common.core.sentinelBlockException"),
    /**
     * 接口限流
     */
    FLOW_EXCEPTION("FlowException", "cn.yx.common.core.flowException"),
    /**
     * 服务降级
     */
    DEGRADE_EXCEPTION("DegradeException", "cn.yx.common.core.degradeException"),
    /**
     * 热点参数限流
     */
    PARAM_FLOW_EXCEPTION("ParamFlowException", "cn.yx.common.core.paramFlowException"),
    /**
     * 授权规则保护
     */
    AUTHORITY_EXCEPTION("AuthorityException", "cn.yx.common.core.authorityException"),
    /**
     * 系统规则保护
     */
    SYSTEM_BLOCK_EXCEPTION("SystemBlockException", "cn.yx.common.core.systemBlockException");

    private final String exception;
    private final String message;

    private static final Map<String, SentinelExceptionEnum> LOOKUP;

    static {
        LOOKUP = new HashMap<>();
        for (SentinelExceptionEnum sentinelExceptionEnum : EnumSet.allOf(SentinelExceptionEnum.class)) {
            LOOKUP.put(sentinelExceptionEnum.getException(), sentinelExceptionEnum);
        }
    }

    SentinelExceptionEnum(String exception, String message) {
        this.exception = exception;
        this.message = message;
    }

    public String getException() {
        return exception;
    }

    public String getMessage() {
        return message;
    }

    public static SentinelExceptionEnum findByValue(String exception) {
        return LOOKUP.get(exception);
    }

}
